package homework.server.terminal.impl;

import homework.qingming.calc.Calculator;
import homework.server.terminal.Command;
import homework.server.terminal.Terminal;

import java.math.BigDecimal;

public class CalcCommand implements Command {

    private Calculator calculator = Calculator.createCalc();

    @Override
    public int execute(String[] args, Terminal terminal) throws Exception {
        if(args == null || args.length < 1)
            throw new IllegalArgumentException("缺少参数");
        BigDecimal result = calculator.calculation(String.join("", args));
        terminal.sendMessage(result.toString());
        return 0;
    }
}
